﻿
Employee = {
    FullName: '',
    EmployeeId:0,
    PositionPopUpDialogBox: '',
    PositionPopUpId: '',
    EmployeeViewUrl: '',
    CashAdvanceViewUrl: '',
    CashAdvancePopUpId: 'CashAdvanceDialogBox',
    AdjusmentsViewUrl: '',
    PositionDropdownControlId: '',
    ClientPopUpId: '',
    ClientDropdownControlId: '',
    CurrentRow: null,
    OnAddPositionClick: function () {
        $('#btnAddPosition').live("click", function (e) {
            e.preventDefault();
            Employee.PositionPopUpId = $(this).attr("id");
            PopUpDialog.UrlDialog("Position", 420, 480, true, Employee.PositionPopUpDialogBox + "?id=0", $(this).attr("id"));
        });
    },
    OnUpdateEmployeeClick: function () {
        $('table#EmployeeTbl .btnUdpate').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("data-id");
            window.location = Employee.EmployeeViewUrl + "?id=" + id;
        });
    },
    OnOpenCashAdvanceClick: function () {
        $('#EmployeeCashAdv').live("click", function (e) {
            e.preventDefault();
            var empid = $(this).attr("data-id");
            PopUpDialog.UrlDialog(Employee.FullName + ' C.A.', 450, 500, true, Employee.CashAdvanceViewUrl + "?empid=" + empid, Employee.CashAdvancePopUpId);
        });
    },
    OnOpenAdjustmentClick: function () {
        $('#EmployeeAdjusments').live("click", function (e) {
            e.preventDefault();
            var empid = $(this).attr("data-id");
            PopUpDialog.UrlDialog(Employee.FullName + ' Adjustments', 600, 500, true, Employee.AdjusmentsViewUrl + "?empid=" + empid, $(this).attr("id"));
        });
    },
    OnDeleteEmployeeClick: function () {
        $('table#EmployeeTbl .btnDelete').live("click", function (e) {
            e.preventDefault();
            if (confirm('Are you sure you want to delete item?')) {
                var id = $(this).attr("data-id");
                var json = JSON.stringify({ Id: id });
                Employee.CurrentRow = $(this).closest("tr");
                $.ajax({
                    type: "POST",
                    url: "../Webservices/EmployeeWebService.asmx/DeleteEmployee",
                    data: json,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var response = eval('(' + data.d + ')');
                        if (response.Success) {
                            Employee.CurrentRow.remove();
                        }
                    }
                });

            }
        });
    }

}


$(document).ready(function () {
    Employee.OnAddPositionClick();
    Employee.OnUpdateEmployeeClick();
    Employee.OnDeleteEmployeeClick();
    Employee.OnOpenCashAdvanceClick();
    Employee.OnOpenAdjustmentClick();       
});